package com.yuke.cloud.service.cmc.service.impl;

import com.yuke.cloud.common.core.utils.RequestUtil;
import com.yuke.cloud.service.cmc.dao.CmsAppBackgroundPageMapper;
import com.yuke.cloud.service.cmc.entity.CmsAppBackground;
import com.yuke.cloud.service.cmc.entity.CmsAppBackgroundPage;
import com.yuke.cloud.service.cmc.service.CmsAppBackgroundPageService;
import com.yuke.cloud.common.core.support.BaseService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;


/**
 * Created by wg on 2019/01/18.
 */
@Service
@Transactional
public class CmsAppBackgroundPageServiceImpl extends BaseService<CmsAppBackgroundPage> implements CmsAppBackgroundPageService {
    @Resource
    private CmsAppBackgroundPageMapper cmsAppBackgroundPageMapper;

    @Override
    public int save(CmsAppBackgroundPage record) {
        record.setUpdateUser(RequestUtil.getLoginUser().getUserId());
        return super.save(record);
    }

    @Override
    public int update(CmsAppBackgroundPage entity) {
        entity.setUpdateUser(RequestUtil.getLoginUser().getUserId());
        return super.update(entity);
    }

    @Override
    public void usePage(CmsAppBackground cmsAppBackground, List<Long> pageIds) {
        if (pageIds.size() == 0)
            return;
        CmsAppBackgroundPage cmsAppBackgroundPage = new CmsAppBackgroundPage();
        cmsAppBackgroundPage.setBackgroundId(cmsAppBackground.getBackgroundId());
        this.delete(cmsAppBackgroundPage);
//        cmsAppBackgroundPage.setUpdateUser(cmsAppBackground.getUpdateUser());
        for (Long pageId : pageIds) {
            cmsAppBackgroundPage.setPageId(pageId);
//            cmsAppBackgroundPage.setBackgroundPageId(generateId());
            this.save(cmsAppBackgroundPage);
        }
    }
}
